package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.budwk.app.sqfw.enums.DownLoadFileNameEnum;
import com.budwk.app.sqfw.services.SqfwCompleteflowService;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.SqfwWorkorderService;
import com.budwk.app.sqfw.vo.GenerateExcelUrlVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.app.sqfwDoc.dto.TemplateCodeUpdateDTO;
import com.budwk.app.sqfwV2.service.centuryCity.OldCareServiceStationExcelService;
import com.budwk.app.sqfwV2.service.centuryCity.OldCareServiceStationPdfService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.openapi.annotation.ApiResponses;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import com.budwk.starter.security.utils.SecurityUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.POST;
import org.nutz.mvc.annotation.Param;

import java.util.List;

/**
 * @author ZY.Wang
 * @since 2024/1/18
 */
@IocBean
@At("/platform/sqfw/centuryCity")
@ApiDefinition(tag = "世纪城")
@Slf4j
public class CenturyCityController {

    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService;
    @Inject
    private SqfwCompleteflowService sqfwCompleteflowService;
    @Inject
    private OldCareServiceStationExcelService oldCareServiceStationExcelService;
    @Inject
    private SysUserService sysUserService;
    @Inject
    private SqfwWorkorderService sqfwWorkorderService;
    @Inject
    private OldCareServiceStationPdfService oldCareServiceStationPdfService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "添加检查数据")
    @ApiResponses
    @SLog(tag = "添加检查数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> addCheckData(@Param("..") TemplateCodeUpdateDTO templateCodeUpdateDTO) {
        String userId = SecurityUtil.getUserId();
        oldCareServiceStationPdfService.generatePdfAndMessage(userId, templateCodeUpdateDTO);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "世纪城下载excel")
    @ApiResponses
    @SLog(tag = "世纪城下载excel", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> downloadExcel(@Param("sqfwId") String sqfwId) {

        if (StringUtils.isBlank(sqfwId)) return Result.error();

        List<GenerateExcelUrlVO> generateExcelUrlVOS = oldCareServiceStationExcelService.createExcel(Lists.newArrayList(sqfwId));

        return Result.success(generateExcelUrlVOS);
    }
}
